package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DlConfig {

    /**
     * 声名包含过期时间的队列
     * 指定 绑定的死信交换机和routingkey
     * @return
     */
    @Bean
    public Queue ttlQueue(){
        return QueueBuilder.durable("ttl.queue")
                .ttl(10000)
                .deadLetterExchange("dl.ttl.exchange")
                .deadLetterRoutingKey("dl")
                .build();
    }

    /**
     * 过期队列交换机
     * @return
     */
    @Bean
    public DirectExchange ttlExchanage(){
        return new DirectExchange("ttl.direct" ,true,false);
    }

    @Bean
    public Binding ttlBinding(){
        return BindingBuilder.bind(ttlQueue()).to(ttlExchanage()).with("ttl");
    }

}
